/*
 * $Id: main.c,v 1.12 2005-07-24 15:19:09 bacon Exp $
 */

#include <xp/bas/memory.h>
#include <xp/bas/locale.h>

#if (!defined(_WIN32) || defined(__LCC__)) && defined(XP_CHAR_IS_WCHAR)

extern int xp_main (int argc, xp_char_t* argv[], xp_char_t** envp);

int main (int argc, xp_mchar_t* argv[], xp_mchar_t** envp)
{
	int n, ret;
	xp_char_t** v;

	v = (xp_char_t**)xp_malloc(argc * xp_sizeof(xp_char_t*));
	if (v == XP_NULL) return -1;

	for (n = 0; n < argc; n++) {
		xp_size_t len = xp_mcswclen (argv[n]);
		v[n] = (xp_char_t*)xp_malloc ((len + 1) * xp_sizeof(xp_char_t));
		if (v[n] == XP_NULL) {
			/* TODO: error handling.. */
			return -1; 
		}

		xp_mcstowcs (argv[n], v[n], len + 1);
	}

	/* TODO: envp... */
	ret = xp_main (argc, v, XP_NULL);

	for (n = 0; n < argc; n++) xp_free (v[n]);
	xp_free (v);

	return ret;
}

#endif

